package org.dingfugui.triple;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;

import java.util.concurrent.CountDownLatch;

/**
 * @author fugui.ding at 2015/6/24
 */
public class Main {


    public static void main(String[] args) throws Exception {
        ZooKeeper zk;
        final CountDownLatch lock = new CountDownLatch(1);
        zk = new ZooKeeper("127.0.0.1" + ":" + 2181, 10000, event -> {
            if (event.getState().equals(Watcher.Event.KeeperState.SyncConnected)) {
                lock.countDown();
            }
        });

        lock.await();

        System.out.println(zk.exists("/triple/service", false));

        //创建root
        if (zk.exists("/triple/service", false) == null) {
            zk.create("/triple", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
            zk.create("/triple/service", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
        //监控服务变动
        //zk.getChildren("/triple/service", this);

    }
}




